﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;
using SYDZ.WMS.DBUtility;
using System.Threading;

namespace ElectronicWMSA.Warehouse
{
    public partial class Frm_OldLibra : Form
    {
        private string strWhere = "";
        public Frm_OldLibra()
        {
            InitializeComponent();

            //this.page1.PageCurrent = 1;
            //this.page1.PageSize = 50;
            //this.page1.Bind();
        }
        //private int DBindData()
        //{
        //    ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
        //    pageData.TableName = "Vlh_NewKulinDate";
        //    pageData.PrimaryKey = "Product_Model";
        //    pageData.OrderStr = "Product_Model";
        //    pageData.PageIndex = this.page1.PageCurrent;
        //    pageData.PageSize = this.page1.PageSize;
        //    pageData.QueryCondition = strWhere;
        //    pageData.QueryFieldName = "*";

        //    this.page1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
        //    this.page1.bindingNavigator.BindingSource = page1.bindingSource;
        //    this.dataGridViewUserList.AutoGenerateColumns = false;
        //    this.dataGridViewUserList.DataSource = this.page1.bindingSource;
        //    this.dataGridViewUserList.ClearSelection();
        //    this.dataGridViewUserList.CurrentCell = null;
        //    return pageData.TotalCount;
        //}
        private DataTable dt = new DataTable();
        private DataTable getdata()
        {
            string sql = "select * from Vlh_NewKulinDate";
            if (strWhere != "")
            {
                sql += " where " + strWhere;
            }
            
            dt = DbHelperSQL.ExecuteDataTable(sql);

            return dt;

        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return 0;
            //return DBindData();
        }
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewUserList.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewUserList.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
            // if (!SystemVariable.VaildationPermission("查询")) return;
            dt = new DataTable();
            this.strWhere = " 1=1 ";


            if (!string.IsNullOrEmpty(txt_Machine.Text.Trim()))
            {
                strWhere += "  and Replace(Product_Model,' ','') like '%" + txt_Machine.Text.Trim() + "%'";
            }
            if (cob_GY.Text == "1个月")
            {
                strWhere += "  and     [1个月]>0 ";
            }
            if (cob_GY.Text == "2个月")
            {
                strWhere += "  and    [2个月]>0 ";
            }
            if (cob_GY.Text == "3个月")
            {
                strWhere += "  and    [3个月]>0 ";
            }
            if (cob_GY.Text == "4个月")
            {
                strWhere += "  and     [4个月]>0 ";
            }
            if (cob_GY.Text == "5个月")
            {
                strWhere += "  and     [5个月]>0 ";
            }

            if (cob_GY.Text == "6个月")
            {
                strWhere += "  and     [6个月]>0 ";
            }

            if (cob_GY.Text == "7个月")
            {
                strWhere += "  and     [7个月]>0 ";
            }

            if (cob_GY.Text == "8个月")
            {
                strWhere += "  and     [8个月]>0 ";
            }

            if (cob_GY.Text == "9个月")
            {
                strWhere += "  and     [9个月]>0 ";
            }
            if (cob_GY.Text == "10个月")
            {
                strWhere += "  and     [10个月]>0 ";
            }

            if (cob_GY.Text == "11个月")
            {
                strWhere += "  and     [11个月]>0 ";
            }

            if (cob_GY.Text == "12个月")
            {
                strWhere += "  and     [12个月]>0 ";
            }

            if (cob_GY.Text == "12个月以上")
            {
                strWhere += "  and  [1年以上]>0 ";
            }

          
            WaitingBoxFrm wf = new WaitingBoxFrm((obj, args) =>
            {
                Thread.Sleep(1000);  getdata();
            }, 30); wf.ShowDialog(this);
            //    label1.Text ="总数：" +dt.AsEnumerable().Sum(x => Convert.ToDecimal(x[cob_GY.Text])).ToString();
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = dt;

            for (int i = 0; i < dataGridViewUserList.RowCount; i++)
            {
                for (int j = 0; j < dataGridViewUserList.ColumnCount; j++)
                {
                    if (j > 1)
                    {
                        if (dataGridViewUserList.Rows[i].Cells[j].Value.ToString() != "0")
                        {
                            dataGridViewUserList.Rows[i].Cells[j].Style.BackColor = Color.Yellow;
                        }
                    }
                }
            }
        }
        private void GetNULL() { }
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }

        private void btn_exct_Click(object sender, EventArgs e)
        {
            ExPut.GetNopiExcel(" *  ", " [dbo].[Vlh_NewKulinDate]    ", strWhere);
        }

        private void dataGridViewUserList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

    }
}
